package com.sys.controller;

import com.sys.common.constant.Constant;
import com.sys.common.util.ResponseDateUtil;
import com.sys.common.util.ResultBuilder;
import com.sys.pojo.QueryVo;
import com.sys.pojo.Security;
import com.sys.service.SecurityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Eric Fang
 * @version 1.0
 * @date 2022/3/23 17:34
 */
@Api(tags = {"疫情管理"})
@RestController
@RequestMapping("/security")
public class SecurityController {

    @Autowired
    private SecurityService securityService;

    @PostMapping("/listAllSecurity")
    @RequiresPermissions("security:list")
    @ApiOperation("获取全部信息")
    public ResponseDateUtil getAllSecurity(@RequestBody QueryVo queryVo) {
        return ResultBuilder.success(securityService.findListByPage(queryVo));
    }

    @GetMapping("/getById/{id}")
    @ApiOperation("通过id查找")
    public ResponseDateUtil getById(@PathVariable Integer id) {
        return ResultBuilder.success(securityService.getSecurityById(id));
    }

    @PostMapping("/addSecurity")
    @ApiOperation("添加疫情防控")
    public ResponseDateUtil addSecurity(@RequestBody Security security) {
        Integer count = securityService.addSecurity(security);
        if (count > 0) {
            return ResultBuilder.success();
        } else {
            return ResultBuilder.errorInfo(Constant.ADDFAILED);
        }
    }

    @PostMapping("/updateSecurity")
    @ApiOperation("修改疫情防控")
    public ResponseDateUtil updateSecurity(@RequestBody Security security) {
        Integer count = securityService.updateSecurity(security);
        if (count > 0) {
            return ResultBuilder.success();
        } else {
            return ResultBuilder.errorInfo(Constant.ADDFAILED);
        }
    }

    @DeleteMapping("/deleteSecurity/{id}")
    @ApiOperation("删除疫情防控")
    public ResponseDateUtil deleteSecurity(@PathVariable Integer id) {
        Integer count = securityService.deleteSecurity(id);
        if (count > 0) {
            return ResultBuilder.success();
        } else {
            return ResultBuilder.errorInfo(Constant.ADDFAILED);
        }
    }
}
